package main

import (
	"fmt"
	"sync"
	"time"
)

// 管道的使用
var wg1 sync.WaitGroup
func main() {
	var intChan chan int
	intChan = make(chan int,50)
	wg1.Add(2)
	go writChan(intChan)
    go readData(intChan)
	wg1.Wait()
}
//读：
func readData(intChan chan int){
	defer wg1.Done()
	//遍历：
	for v := range intChan{
		fmt.Println("读取的数据为：",v)
		time.Sleep(time.Second)
	}
}
func writChan(intChan chan int){
	defer wg1.Done()
	for i:=0;i<50;i++{
		intChan<- i
		fmt.Println("写入的数据为：",i)
		//time.Sleep(time.Second)
	}
	close(intChan)
}